-module(quek_encode).
-export([to_utf8/2, from_utf8/2, to_codes/2, to_bytes/2]).


to_utf8(Module, Bytes) ->
    Codes = to_codes(Module, Bytes),
    Utf8Codes = [Module:to_utf8(X) || X <- Codes],
    to_bytes(quek_utf8, Utf8Codes).

from_utf8(Module, Bytes) ->
    Codes = to_codes(quek_utf8, Bytes),
    NativeCodes = [Module:from_utf8(X) || X <- Codes],
    to_bytes(Module, NativeCodes).


to_codes(Module, Bytes) ->
    to_codes(Module, Bytes, []).

to_codes(_Module, [], Acc) ->
    .lists:reverse(Acc);
to_codes(Module, Bytes, Acc) ->
    {Code, T} =Module:to_code(Bytes),
    to_codes(Module, T, [Code|Acc]).
    

to_bytes(Module, Codes) ->
    to_bytes(Module, Codes, []).

to_bytes(_Module, [], Acc) ->
    .lists:flatten(.lists:reverse(Acc));
to_bytes(Module, [H|T], Acc) ->
    Bytes = Module:to_byte(H),
    to_bytes(Module, T, [Bytes|Acc]).
